package com.clear.command.demo1;

public class Main {
    public static void main(String[] args) {
        // 创建一个灯
        Light light = new Light();
        // 创建一个开灯命令
        LightOnCommand lightOnCommand = new LightOnCommand(light);

        RemoteControl remoteControl = new RemoteControl();
        remoteControl.setCommand(lightOnCommand);

        remoteControl.pressButton();


        // =======================================================
        Light light1 = new Light();
        AirConditioner airConditioner1 = new AirConditioner();
        // 创建宏命令：开启所有设备
        MacroCommand turnAllOnCommand  = new MacroCommand();
        turnAllOnCommand.addCommand(new LightOnCommand(light1));
        turnAllOnCommand.addCommand(new AirConditionerOnCommand(airConditioner1));

        // 创建宏命令：关闭所有设备
        MacroCommand turnAllOffCommand = new MacroCommand();
        turnAllOffCommand.addCommand(new LightOffCommand(light1));
        turnAllOffCommand.addCommand(new AirConditionerOffCommand(airConditioner1));

        RemoteControl remoteControl1 = new RemoteControl();

        // 执行宏命令：开启所有设备
        System.out.println("Turn all devices on:");
        remoteControl.setCommand(turnAllOnCommand);
        remoteControl.pressButton();

        // 执行宏命令：关闭所有设备
        System.out.println("\nTurn all devices off:");
        remoteControl.setCommand(turnAllOffCommand);
        remoteControl.pressButton();
    }
}
